﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Leo.JqueryGrid.Web.Models;
using Leo.JqueryGrid.Web.Services.Fake;
using Leo.JqueryGrid.Web.Services.Interfaces;
using OOGrid.Models;

namespace Leo.JqueryGrid.Web.Controllers
{
    public class DemoController : Controller
    {
        private readonly IProductService _productService;
        private readonly IProductPriceService _productPriceService;
        public DemoController()
        {
            _productService = new ProductService();
            _productPriceService = new ProductPriceService();
        }

        public ActionResult Index()
        {
            return View();
        }

        

        public PartialViewResult FirstLook()
        {
            return PartialView();
        }

        public PartialViewResult CellFormater()
        {
            System.Threading.Thread.Sleep(1000);
            return PartialView();
        }

        public PartialViewResult CellTemplate()
        {
            System.Threading.Thread.Sleep(1000);
            return PartialView();
        }

        public ActionResult Ajax()
        {
            return View();
        }

        #region json results

        public JsonResult AjaxProducts(OOGridFilter filter)
        {
            var products = _productService.GetPagedProducts(filter);
            var model = new OOGridModel<Product>();
            model.Rows = products;
            model.Total = 1500;
            model.UpdateTotal = filter.UpdateTotal ?? false;
            return Json(model, JsonRequestBehavior.AllowGet);
        }

        public JsonResult Products()
        {
            var products = _productService.GetProducts(500);
            return Json(products, "json", JsonRequestBehavior.AllowGet);
        }

        public JsonResult Prices()
        {
            var prices = _productPriceService.GetPrices(500);
            return Json(prices, "json", JsonRequestBehavior.AllowGet);
        }

        #endregion

    }
}
